// ignore_for_file: file_names, camel_case_types

import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';

class udpPageWidget extends StatelessWidget {
  udpPageWidget({super.key});
  // String ipAddr = InternetAddress.anyIPv4 as String;
  String ip = "10.34.68.234";
  int port = 4444;
  final myController = TextEditingController();
  void _sentBorcast() {
    var soruceNet = InternetAddress(ip);
    var detNet = InternetAddress("192.168.99.255");
    RawDatagramSocket.bind(soruceNet, 4444).then((RawDatagramSocket socket) {
      print('Sending from ${socket.address.address}:${socket.port}');
      int port = 4444;
      socket.send(myController.text.codeUnits, detNet, port);
    });
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: kMaterialListPadding,
      children: [
        Row(
          children: [
            Text(
              ip,
              textScaleFactor: 1.5,
              style: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
            ),
            Text(port.toString(),
                textScaleFactor: 1.5,
                style: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic)),
          ],
        ),
        TextField(
          maxLines: 1,
          style: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
          controller: myController,
        ),
        IconButton(
          onPressed: _sentBorcast,
          icon: const Icon(
            Icons.upload,
            size: 30,
          ),
          tooltip: "sent",
        ),
        // FloatingActionButton(
        //   onPressed: () {
        //     showDialog(
        //       context: context,
        //       builder: (context) {
        //         return AlertDialog(
        //           // Retrieve the text the that user has entered by using the
        //           // TextEditingController.
        //           content: Text(myController.text),
        //         );
        //       },
        //     );
        //   },
        //   tooltip: 'Show me the value!',
        //   child: const Icon(Icons.text_fields),
        // )
      ],
    );
  }
}
